#include "slepdef.h"
#include "testDefs.h"
#include <assert.h>

void TestCreateCSCSlepMatrix(){
	double values[] = {1.5, 2.5, 3.5};
	int rows[] = { 4, 9, 7 };
	int columnIndex[] = {0, 1, 2, 3};
	int nnz;
	slep_matrix* testMatrix  ;
	testMatrix  = createCSCSlepMatrix(10,3,values,rows,columnIndex);
	assert(testMatrix != NULL);
	nnz = findNnz(testMatrix);
	assert(nnz == 3);
	assert( testMatrix->m == 10 );
	assert( testMatrix->n == 3 );
	assert( testMatrix->sparsity == SlepSparse );
	assert( testMatrix->data.spmtrx.format == SlepCompressedSparseColumn );
	free(testMatrix);

	// Test 2
	rows[0]=0;
	testMatrix  = createCSCSlepMatrix(1,1,values,rows,columnIndex);
	nnz = findNnz(testMatrix);
	assert(nnz==1);
	free(testMatrix);
}


void TestCreateCSRSlepMatrix(){
	double values[] = {1.5, 2.5, 3.5};
	int columns[] = { 4, 9, 7 };
	int rowIndex[] = {0, 1, 2, 3};
	int nnz;
	slep_matrix* testMatrix  ;

	// Test 1
	testMatrix  = createCSRSlepMatrix(3,10,values,columns,rowIndex);
	assert(testMatrix != NULL);
	nnz = findNnz(testMatrix);
	assert( nnz == 3);
	assert( testMatrix->m == 3 );
	assert( testMatrix->n == 10 );
	assert( testMatrix->sparsity == SlepSparse );
	assert( testMatrix->data.spmtrx.format == SlepCompressedSparseRow);
	free(testMatrix);

	// Test 2
	columns[0]=0;
	testMatrix  = createCSRSlepMatrix(1,1,values,columns,rowIndex);
	nnz = findNnz(testMatrix);
	assert(nnz==1);
	free(testMatrix);
}

void TestCreateDenseSlepMatrix(){
	double values[]={1,2,3,4,5,6,7,8,9,10,11,12};
	slep_matrix* testMatrix = NULL;

	testMatrix = createDenseSlepMatrix(5,6,2,values);

	assert( testMatrix != NULL);
	assert( testMatrix->ld == 6 );
	assert( testMatrix->m == 5);
	assert( testMatrix->n == 2);
	assert( testMatrix->sparsity == SlepDense);
	assert( testMatrix->uplobanded == SlepFull );
	assert( testMatrix->data.mtrx != NULL );
}

void TestCreateDenseSlepVector(){
	double values[]={1,2,3,4,5,6,7,8,9,10,11,12};
	slep_vector* testVector = NULL;

	// Test 1
	testVector = createDenseSlepVector(12,values,1);
	assert( testVector != NULL );
	assert( testVector->sparsity == SlepDense );
	assert( testVector->dim == 12);
	assert( testVector->data.vctr[11] ==  12);

	// Test 2
	testVector = createDenseSlepVector(1,values,1);
	assert( testVector != NULL );
	assert( testVector->sparsity == SlepDense );
	assert( testVector->dim == 1);
	assert( testVector->data.vctr[0] ==  1);

	free(testVector);
}

void TestCreateSparseSlepVector(){
	double values[]={5, 1, 6, 2, 7};
	int index[] = { 32, 42, 62, 63, 92};
	slep_vector* testVector = NULL;

	// Test 1
	testVector = createSparseSlepVector(5 , index, values);
	assert( testVector->sparsity == SlepSparse);
	assert( testVector->dim >=93 );
	assert( testVector->data.spvctr.nnz == 5);
	assert( testVector->data.spvctr.index[4] == 92);
	assert( testVector->data.spvctr.values[4] == 7);
	free(testVector);
}


void TestCreateSymmetricSlepMatrix(){
	double values[]= {1,2,2,4};
	slep_matrix* testMatrix = NULL;

	// Test 1
	testMatrix = createSymmetricSlepMatrix(2,values,SlepFull,0);
	free(testMatrix);
	
}

void TestCreateTriangularSlepMatrix(){
	double values[]= {1,2,4};
	slep_matrix* testMatrix = NULL;

	// Test 1
	testMatrix = createTriangularSlepMatrix(2,values,SlepUpper,1);
	free(testMatrix);
}



void TestAll(){
	TestCreateCSCSlepMatrix();
	TestCreateCSRSlepMatrix();
	TestCreateDenseSlepMatrix();
	TestCreateDenseSlepVector();
	TestCreateSparseSlepVector();
	TestCreateSymmetricSlepMatrix();
	TestCreateTriangularSlepMatrix();
}